package com.ddone.finance.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ddone.common.result.Response;
import com.ddone.finance.pojo.entity.Borrower;
import com.ddone.finance.pojo.vo.BorrowerApprovalVO;
import com.ddone.finance.pojo.vo.BorrowerDetailVo;
import com.ddone.finance.service.BorrowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author ddone
 * @date 2024/4/20-17:28
 */
@Api(tags = {"借款人管理"})
@RestController
@RequestMapping("/core/admin/borrower")
public class AdminBorrowController {
    @Resource
    private BorrowerService borrowerService;

    @ApiOperation("获取借款人分页列表")
    @GetMapping("/{page}/{size}")
    public Response<Object> page(
            @ApiParam(value = "当前页码", required = true,example = "1")
            @PathVariable Long page,

            @ApiParam(value = "每页记录数", required = true,example = "10")
            @PathVariable Long size,

            @ApiParam(value = "查询关键字", required = false)
            @RequestParam(value = "keyword",required = false) String keyword) {
        //这里的@RequestParam其实是可以省略的，但是在目前的swagger版本中（2.9.2）不能省略，
        //否则默认将没有注解的参数解析为body中的传递的数据

        Page<Borrower> pageParam = new Page<>(page, size);
        IPage<Borrower> pageModel = borrowerService.listPage(pageParam, keyword);
        return Response.ok(pageModel);
    }

    @ApiOperation("获取借款人信息")
    @GetMapping("/{id}")
    public Response<Object> getById(
            @PathVariable("id")
            @ApiParam("借款人Id") Long id){
        BorrowerDetailVo borrowerDetailVO = borrowerService.getBorrowerDetail(id);
        return Response.ok(borrowerDetailVO);
    }

    @ApiOperation("借款额度审批")
    @PostMapping("/approval")
    public Response<Object> approval(@RequestBody BorrowerApprovalVO borrowerApprovalVO) {
        borrowerService.approval(borrowerApprovalVO);
        return Response.ok().message("审批完成");
    }
}
